public class SlidingWindow {
    public String minWindow(String s, String t) {
        int sLen = s.length();
        int tLen = t.length();
        int[] tArr = new int[128];
        for (int i = 0; i < tLen; i++) {
            char ch = t.charAt(i);
            tArr[ch]++;
        }
        int[] sArr = new int[128];
        int min = sLen + 1;
        int index = 0;
        for (int left = 0, right = 0, count = 0; right < sLen; right++) {
            char in = s.charAt(right);
            sArr[in]++;
            if (sArr[in] <= tArr[in]) {
                count++;//是有效字符
            }
            while (count == tLen) {
                if (min > right - left + 1) {
                    min = right - left + 1;
                    index = left;
                }
                char out = s.charAt(left);
                if (sArr[out] <= tArr[out]) {//是有效字符
                    count--;
                }
                sArr[out]--;
                left++;
            }
        }
        return min == sLen + 1 ? "" : s.substring(index, index + min);
    }
}
